package com.jt.controller;

import java.sql.SQLOutput;

public class TestThread {

    private  static  int sum = 50;
    static class MyThread extends Thread {
        private String name;
        public MyThread(String name){
            super(name);
        }
        @Override
        public void run() {
            for (int i = 0; i <50 ; i++) {
                try {
                    if (sum>0){
                        Thread.sleep(500);
                        sum--;
                        System.out.println(Thread.currentThread().getName()+"执行:sum==="+sum);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread myThread1=new MyThread("线程1");
        myThread1.start();
        myThread1.join();
        System.out.println( myThread1.getName());

        MyThread myThread2=new MyThread("线程2");
        myThread2.start();
        System.out.println( myThread2.getName());

        MyThread myThread3=new MyThread("线程3");
        myThread3.start();
        System.out.println( myThread3.getName());
    }
}
